package com.uidt.project.ptsj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uidt.framework.aspectj.lang.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uidt.framework.aspectj.lang.annotation.Log;
import com.uidt.framework.aspectj.lang.enums.BusinessType;
import com.uidt.project.ptsj.domain.HouseInfo;
import com.uidt.project.ptsj.service.IHouseInfoService;
import com.uidt.framework.web.controller.BaseController;
import com.uidt.framework.web.domain.AjaxResult;
import com.uidt.common.utils.poi.ExcelUtil;
import com.uidt.framework.web.page.TableDataInfo;

/**
 * 房源信息Controller
 * 
 * @author uidt
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/ptsj/info")
public class HouseInfoController extends BaseController
{
    @Autowired
    private IHouseInfoService houseInfoService;

    /**
     * 查询房源信息列表
     */
    @PreAuthorize("@ss.hasPermi('ptsj:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseInfo ptsjHouseInfo)
    {
        startPage();
        List<HouseInfo> list = houseInfoService.selectHouseInfoList(ptsjHouseInfo);
        return getDataTable(list);
    }

    /**
     * 导出房源信息列表
     */
    @PreAuthorize("@ss.hasPermi('ptsj:info:export')")
    @Log(title = "房源信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseInfo ptsjHouseInfo)
    {
        List<HouseInfo> list = houseInfoService.selectHouseInfoList(ptsjHouseInfo);
        ExcelUtil<HouseInfo> util = new ExcelUtil<HouseInfo>(HouseInfo.class);
        util.exportExcel(response, list, "房源信息数据");
    }

    /**
     * 获取房源信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:info:query')")
    @GetMapping(value = "/{houseCode}")
    public AjaxResult getInfo(@PathVariable("houseCode") String houseCode)
    {
        return success(houseInfoService.selectHouseInfoByHouseCode(houseCode));
    }

    /**
     * 新增房源信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:info:add')")
    @Log(title = "房源信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseInfo ptsjHouseInfo)
    {
        return toAjax(houseInfoService.insertHouseInfo(ptsjHouseInfo));
    }

    /**
     * 修改房源信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:info:edit')")
    @Log(title = "房源信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseInfo ptsjHouseInfo)
    {
        return toAjax(houseInfoService.updateHouseInfo(ptsjHouseInfo));
    }

    /**
     * 删除房源信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:info:remove')")
    @Log(title = "房源信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{houseCodes}")
    public AjaxResult remove(@PathVariable String[] houseCodes)
    {
        return toAjax(houseInfoService.deleteHouseInfoByHouseCodes(houseCodes));
    }
}
